{% extends 'install.html' %}
{% block cs %}
<script type="text/javascript">
$(document).ready(function() {
		$("#jiaofu").click(function(){
			$("input[name='jf']").each(function(){
			if($(this).prop("checked")){     
    			$(this).prop("checked",false);     
         	}     
   			else{     
    			$(this).prop("checked",true);
   			}       
		})
		});
		$("#piliangjiaofu").click(function(){
			var string = '';
			var $btn = $(this).button('loading');
			$("input[name='jf']:checked").each(function(){
				string += $(this).val() + ","
			})
			if (string == ''){
				alert("Nothing Select");
				$btn.button('reset');
			}
			else{
				$.post("{% url "batch_delivery" %}",{
					delivery_list:string 
				},
				function(data,status){
					data=JSON.parse(data);
					if (data.code == 0 ){
						alert("批量执行完毕");
						 window.location.href="{% url "his" %}";
					}
				})

			}
		});
	})
</script>
{% endblock %}
{% block list %}
<table id="myTable" class="table table-hover">
	<thead>
	<tr>
		<th>品牌</th>
		<th>IP</th>
		<th>ILO_IP</th>
		<th>SN</th>
		<th>Raid级别</th>
		<th>Raid所用磁盘</th>
		<th>状态</th>
		<th id="jiaofu">全选</th>
		<th>上线</th>
	</tr>
	</thead>
	<tbody>
		{% for i in forms %}
	<tr>
		<td>{{ i.inc }}</td>
		<td>{{ i.service_ip }}</td>
		<td>{{ i.ilo_ip }}</td>
		<td>{{ i.sn }}</td>
		<td>{{ i.level }}</td>
		<td>{{ i.raid_zh }}</td>
		{% if i.ssh_status %}
		<td><button class="btn btn-success btn-sm">可登陆</button></td>
		<td><input name="jf" type="checkbox" value="{{i.id}}"></td>
		{% else %}
		<td><button id="{{i.id}}" class="btn btn-warning btn-sm">重启中..</button></td>
		<script type="text/javascript">
            $(document).ready(function(){
        	var progresspump = setInterval(function(){
            /* query the completion percentage from the server */
            $.get("/ping/{{ i.id }}/",function(result){
               /* update the progress bar width */
               var result= eval('('+result+')');
               $.each(result,function(index,d){
              /* console.log(data); */
               var data = d;
                /* test to see if the job has completed */
                if(data == 0 ) {
                /*    window.location.reload(); */
                    clearInterval(progresspump);
                    $("#"+{{i.id}}).text("可登陆").removeClass("btn-warning").addClass("btn-success");
                    $("#kedenglu_"+{{i.id}}).prop('name','jf').prop('disabled','');
                }
            })
            })
        }, 10000);});
		</script>
		<td><input id="kedenglu_{{i.id}}" disabled="disabled" type="checkbox" value="{{i.id}}"></td>
		{% endif %}
		<td><a data-trigger="confirm" data-cssclass="del" class="btn btn-info btn-sm" href="/delivery/{{i.id}}">交付</a></td>
	</tr>
	{% endfor %}
	</tbody>
</table>
<a href="{% url "export_ip" %}" target="_blank" class="btn  btn-default">导出已安装IP列表</a>
<button class="btn btn-info "type="buttom" id="piliangjiaofu">批量交付</button>
{% endblock %}